package com.jf.nep.scene.object;

import org.lwjgl.util.vector.Vector3f;
import org.lwjgl.util.vector.Vector4f;

import com.jf.nep.render.Vertex;

public class Triangle {
    private Vertex[] vertices;

    public Triangle(Vector3f p0, Vector3f p1, Vector3f p2) {        
        Vector3f u = new Vector3f();
        Vector3f.sub(p1, p0, u);
        
        Vector3f v = new Vector3f();
        Vector3f.sub(p2, p0, v);
        
        Vector3f n = new Vector3f();
        Vector3f.cross(u, v, n);
        n.normalise();
        
        Vector4f n4 = new Vector4f(n.x, n.y, n.z, 1);

        Vertex v1 = new Vertex(new Vector4f(p0.x,p0.y,p0.z,1),n4);
        Vertex v2 = new Vertex(new Vector4f(p1.x,p1.y,p1.z,1),n4);
        Vertex v3 = new Vertex(new Vector4f(p2.x,p2.y,p2.z,1),n4);
        
        vertices = new Vertex[] {v1,v2,v3};
    }
    
    public Vertex[] getVertices() {
        return vertices;
    }
    
}
